package com.zygh.lz.service.impl;

import com.zygh.lz.constant.SystemCon;
import com.zygh.lz.dao.OperationMapper;
import com.zygh.lz.entity.Operation;
import com.zygh.lz.service.OperationService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SendLogUtils;
import com.zygh.lz.vo.ResultBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OperationServiceImpl implements OperationService {

    @Resource
    private OperationMapper operationMapper;

    @Override
    public ResultBean uploadLog() throws Exception {
        //获取未上传的日志信息
        List<Operation> allOperationByState = operationMapper.findAllOperationByState();
        if (allOperationByState.size() > 0) {
            for (Operation anAllOperationByState : allOperationByState) {
                Boolean aBoolean = SendLogUtils.sendLog(anAllOperationByState);
                if (aBoolean) {
                    anAllOperationByState.setState(1);
                    anAllOperationByState.setId(anAllOperationByState.getId());
                    operationMapper.updateByPrimaryKeySelective(anAllOperationByState);
                }

            }
            System.out.println("==========================日志上传省厅结束！================================");
            return ResultUtil.setOK("success", "上传成功并结束！");
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", "无上传日志！");
    }
}
